import router from "@/router";
import { currentUserStore } from "@/store/userLoginStore";
import { message } from "ant-design-vue";

/**
 * 全局权限管理页面
 */
router.beforeEach((to, from, next) => {
  const userLoginStore = currentUserStore();
  const loginUser = userLoginStore.loginUser;
  const toUrl = to.fullPath;
  console.log("toUrl", toUrl);
  if (toUrl.startsWith("/admin")) {
    console.log(loginUser);
    if (!loginUser || loginUser.userRole != 1) {
      message.error("无访问权限");
      next(`/user/login?redirect=${to.fullPath}`);
      return;
    }
  }
  next();
});
